package com.itqf.sms.service.impl;

import com.itqf.sms.dto.BillDto;
import com.itqf.sms.mapper.BillMapper;
import com.itqf.sms.mapper.ProviderMapper;
import com.itqf.sms.pojo.Bill;
import com.itqf.sms.pojo.Provider;
import com.itqf.sms.service.BillService;
import com.itqf.sms.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * projectName: qk_javaproject
 *
 * @author: 肖成扬
 * time: 2021/9/8 14:52
 * description:
 */
@Service
public class BillServiceImpl implements BillService {
    @Autowired
    private BillMapper billMapper;
    @Autowired
    private ProviderMapper providerMapper;
    @Override
    public R providers() {
        List<Provider> providers = providerMapper.selectList(null);
        return R.OK("查询成功！",providers);
    }

    @Override
    public R list(BillDto billDto) {
        List<Bill> bills = billMapper.queryBills(billDto);
        return R.OK("查询成功！",bills);
    }

    @Override
    public R save(Bill bill) {
        int rows = 0;
        try {
          rows=  billMapper.insert(bill);
        }catch (Exception e){}
        if(rows==0){
            return R.FAIL("参数异常！");
        }else { return R.OK("插入成功！");}

    }

    @Override
    public R update(Bill bill) {
        int rows = 0;
        try {
            rows=  billMapper.updateById(bill);
        }catch (Exception e){}
        if(rows==0){
            return R.FAIL("参数异常！");
        }else { return R.OK("修改成功！");}
    }

    @Override
    public R delete(int bid) {
        Bill bill = new Bill();
        bill.setBid(bid);
        bill.setDeleted(1);
        int row = billMapper.updateById(bill);

        return R.OK("数据删除成功");
    }
}
